
<%@ page import="sedh.project.Programa" %>
<%@ page import="sedh.project.AlocadorMunProg" %>
<html>
    <head>
    
    <modalbox:modalIncludes />
    
	<script type="text/javascript">
	    function ChangeColor(tableRow, highLight)
	    {
	    if (highLight)
	    {
	      tableRow.style.backgroundColor = '#CCCCCC';
	    }
	    else
	    {
	      tableRow.style.backgroundColor = '#FFFFFF';
	    }
	  }
	
	  function DoNav(theUrl)
	  {
	  document.location.href = "/SEDH-PROJECT/programa/list/" + theUrl;
	  }

	  function EditProg(id) {
		  document.location.href = "/SEDH-PROJECT/programa/edit/"+id;
	   }
	  
	  function createLink(theUrl)
	  {
	  document.location.href = "?mun="+theUrl;
	  }
	  function showSpinner(visible) {
	         $('spinner').style.display = visible ? "inline" : "none";
	     }
	     Ajax.Responders.register({
	     onLoading: function() {
	           showSpinner(true);
	     },
	     onComplete: function() {
	     if(!Ajax.activeRequestCount) showSpinner(false);
	     }
	   });

	  </script>
<g:render template="/header"/>
</head>
   
<body>
    <g:render template="/informationBar"/>
    
    <g:render template="/menu"/>
      
    <div class="body">
    
        <div class="searchDivProg">
        
			<h1>Pesquisa de Programas:</h1>
			<g:remoteField class="searchBox" name="search"
				paramName="searchvalue" update="searchresult" value=""
				url="[controller:'programa', action:'searchPrograma']"
				onLoading="showSpinner(true);" onComplete="showSpinner(false);">
			</g:remoteField>
		</div>
		<div class="programaList">
			<g:render template="searchResult" var="searchresults"
				bean="${programaInstanceList}" />

		</div>
		<div class="programaList">


			<h1>Informacoes dos Programas:</h1>
			<h3>Nome:</h3>
			${fieldValue(bean: programaInstance, field: "nome")}
			<g:if
				test="${fieldValue(bean: programaInstance, field: 'nome').toString().equals('') }">
			</g:if>
			<g:else>
					<a href="${createLink(controller:'alocadorMunProg',action:'createbyprog',params:[prog:fieldValue(bean: programaInstance, field: "nome").toString()] )}" >Alocar para Municipio</a>
			</g:else>
			</br>
			<h3>Descricao:</h3>
			${fieldValue(bean: programaInstance, field: "descricao")}</br>
			<h3>Municipios com esse programa:</h3>
			<g:if
				test="${fieldValue(bean: alocMunProgInstance, field: 'municipio').toString().equals('') }">
				Nenhum Municipio Encontrado
			</g:if>
			<g:else>
				<g:each in="${alocMunProgInstance}" status="i" var="alocAtual">
					<g:if
						test="${fieldValue(bean: programaInstance, field: 'nome').toString().equals(fieldValue(bean: alocAtual, field: 'programa').toString())}">
						<a href="#"
							onclick="createLink('${fieldValue(bean: alocAtual, field: 'id')}');">
							${fieldValue(bean: alocAtual, field: 'municipio')}
						</a>
						<br>
					</g:if>
				</g:each>
			</g:else>
		</div>
		<div class="programaList">
			<h1>Dados Gerais do Municipio:</h1>
			<g:each in="${alocMunProgInstance}" status="i" var="alocAtual">
				<g:if
					test="${fieldValue(bean: alocAtual, field: 'id').toString().equals(mun)}">
					<h3>Responsavel:</h3>
					${fieldValue(bean: alocAtual, field: 'responsavel')}<br>
					<h3>Telefone:</h3>
					${fieldValue(bean: alocAtual, field: 'telefone')}
					</br>
					<h3>Numero de Familias:</h3>
					${fieldValue(bean: alocAtual, field: 'familias')}
					</br>
				</g:if>
			</g:each>

		</div>
	</div>
</body>
</html>